package per.qiao.simplerest.util;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Company: 上海数惠系统技术有限公司
 * Department: 数据中心
 * Date: 2020-06-01 17:25
 *
 * @Author: qyp
 * Email: qiaoyp@dist.com.cn
 * Desc:
 */
public class RestServiceUtils {

    /**
     * 获取方法的返回值的泛型, 只支持一个泛型
     * @return
     */
    public static Type getGenericType(Method method) {

        return method.getGenericReturnType();

        /*Class genericType = null;
        Type genericReturnType = method.getGenericReturnType();
        if (genericReturnType instanceof ParameterizedType) {
            Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
            for (Type type : actualTypeArguments) {
                if (type instanceof ParameterizedType) {
                    ParameterizedType pt = (ParameterizedType) type;
                    Class clz = ((Class) pt.getRawType());
                    genericType = clz;
                } else {
                    Class clz = (Class) type;
                    genericType = clz;
                }

            }
        }
        return genericType;*/
    }
}
